package com.mck.controller;

import com.mck.entity.Result;
import com.mck.entity.Notice;
import com.mck.service.NoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/public/notice")
@Slf4j
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    /**
     * 获取公告
     */
    @GetMapping
    public Result getNotice() {
        log.info("获取公告");

        List<Notice> noticeList = noticeService.getNotice();
        return Result.success(noticeList);
    }

    /**
     * 添加公告
     */
    @PostMapping
    public Result addNotice(@RequestBody Notice notice) {
        log.info("添加公告");

        noticeService.addNotice(notice);
        return Result.success();
    }

    /**
     * 修改公告
     */
    @PutMapping
    public Result updateNotice(@RequestBody Notice notice) {
        log.info("修改公告");

        noticeService.updateNotice(notice);
        return Result.success();
    }
}
